package com.michael.study.jetpack.module.databinding

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.michael.study.jetpack.R
import com.michael.study.jetpack.databinding.ActivityViewModelBinding

class ViewModelActivity : AppCompatActivity(), View.OnClickListener {

    private lateinit var mBinding: ActivityViewModelBinding
    private lateinit var mViewModel:ProfileViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewModel = ViewModelProvider(this).get(ProfileViewModel::class.java)
        mBinding = DataBindingUtil.setContentView(this,R.layout.activity_view_model)
        mBinding.btnUpdate.setOnClickListener(this)
        mBinding.viewModel = mViewModel
        mBinding.lifecycleOwner = this
    }

    override fun onClick(v: View?) {
        when(v?.id) {
            R.id.btn_update -> {
                mViewModel.update()
            }
        }
    }
}